#include "sct/rtspserver/aacservermediasubsession.h"
#include "sct/rtspserver/aacsource.h"

#include "MPEG4GenericRTPSink.hh"

namespace sct
{

CAACServerMediaSubsession*
CAACServerMediaSubsession::createNew(UsageEnvironment& env,
						void* audio,
					     Boolean reuseFirstSource) {
  return new CAACServerMediaSubsession(env, audio, reuseFirstSource);
}

CAACServerMediaSubsession
::CAACServerMediaSubsession(UsageEnvironment& env, void* audio,
				    Boolean reuseFirstSource)
  : FileServerMediaSubsession(env, "", reuseFirstSource) {
	mAudioSource = audio;
}

CAACServerMediaSubsession
::~CAACServerMediaSubsession() {
}



FramedSource* CAACServerMediaSubsession
::createNewStreamSource(unsigned /*clientSessionId*/, unsigned& estBitrate) {
  estBitrate = 96; // kbps, estimate

  return CAACSource::createNew(envir(), mAudioSource);
}

RTPSink* CAACServerMediaSubsession
::createNewRTPSink(Groupsock* rtpGroupsock,
		   unsigned char rtpPayloadTypeIfDynamic,
		   FramedSource* inputSource) {
	CAACSource* adtsSource = (CAACSource*)inputSource;
  return MPEG4GenericRTPSink::createNew(envir(), rtpGroupsock,
					rtpPayloadTypeIfDynamic,
					adtsSource->samplingFrequency(),
					"audio", "AAC-hbr", adtsSource->configStr(),
					adtsSource->numChannels());
}


}
